package com.lxl.chat.aspect;

import com.lxl.chat.util.IMoocJSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 处理全局异常
 *
 * @date & @author: 2019/1/18 9:04 & lxl
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public IMoocJSONResult handle(Exception e) {

        if (e instanceof BaseException) {
            BaseException customException = (BaseException) e;
            return new IMoocJSONResult(1111, "出错", customException.getData());
        }

        log.error(e.getMessage());
        e.printStackTrace();
        return new IMoocJSONResult(1111, "出错", "未知错误");
    }


}
